<?php
class Controller_Company extends FLEA_Controller_Action
{
	private $_ModelDeclareCompany;
	private $_ModelProduct;
	private $_ModelUserInfo;
	private $siteInfo;
	private $user;
	
	function Controller_Company(){

		$this->siteInfo = FLEA::getAppInf('siteInfo');
		
		$rbac =& FLEA::getSingleton('FLEA_Rbac');
		$this ->user = $rbac->getUser();//get login user's information
	}
	
	function actionInfo(){			
		$companyNature = FLEA::getAppInf('companyNature');
		
		$this ->_ModelUserInfo = & FLEA::getSingleton('Model_UserInfo');
		
		$userInfo = $this ->_ModelUserInfo -> find($this->user['ID']);//get more user's information
		
		$this->_ModelDeclareCompany = & FLEA::getSingleton('Model_DeclareCompany');
		$result=$this->_ModelDeclareCompany ->find($this->user['ID']);
		
		$viewData = array(
			'siteInfo' => $this -> siteInfo,
			'userInfo' => $userInfo,
			'company' => $userInfo['declarecompany'],
			'companyNature'=>$companyNature,
			'dispatching'=>$result['dispatching'],
		);
//		dump($viewData);exit;
		$this->_executeView('CompanyInfo.html', $viewData);
	}

	function actionChangeInfo(){		
		foreach($_POST as $key => $value){
			$$key = addslashes(trim($value));
		}
		
//		dump($_POST);
		
		foreach($_POST['dispatching_name'] as $keys=>$values){
			if(!$values || !$_POST['dispatching_area'][$keys])continue;
			$dispatching[$keys]['name'] = $values;
			$dispatching[$keys]['area'] = $_POST['dispatching_area'][$keys];
			if($_POST['dispatching_id'][$keys]){
				$dispatching[$keys]['dispatching_id'] = $_POST['dispatching_id'][$keys];
			}
		}
			
		$list=array(
			'name'=>$name,
			'permitNumber'=>$permitNumber,
			'permitValideDate'=>$permitValideDate,
			'telephone'=>$telephone,
			'contactPerson'=>$contactPerson,
			'contactPersonCellphone'=>$contactPersonCellphone,
			'contactPersonTelephone'=>$contactPersonTelephone,
			'user_id'=>$this->user['ID'],
			'manageNumber'=>$manageNumber,
			'manageValideDate'=>$manageValideDate,
			'dispatching'=>$dispatching,
			'legalPerson'=>$legalPerson,
			'legalPersonCellphone'=>$legalPersonCellphone,
			'cTelephone'=>$cTelephone,
			'resPerson'=>$resPerson,
			'resPersonCellphone'=>$resPersonCellphone,
			'resPersonTelephone'=>$resPersonTelephone,
		);
		
		if(!empty($declare_id)){
			$list['declare_id'] = $declare_id;
		}
		
//		dump($list);exit;
	
		$this->_ModelDeclareCompany = & FLEA::getSingleton('Model_DeclareCompany');
		$this->_ModelDeclareCompany -> save($list);
		
		$msg = '企业信息修改成功';
		js_alert($msg,'',url('Company','Info'));
	}

}
?>